home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Framework / Sources / UFile.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  43.9 KB  |  1,547 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UFile.cp
  3. // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __UFILE__
  7. #include "UFile.h"
  8. #endif
  9.  
  10. // MacApp
  11.  
  12. #ifndef __UAPPLEEVENTS__
  13. #include "UAppleEvents.h"
  14. #endif
  15.  
  16. #ifndef __UCOREERRORMGR__
  17. #include "UCoreErrorMgr.h"
  18. #endif
  19.  
  20. #ifndef __UCOREGLOBALS__
  21. #include "UCoreGlobals.h"
  22. #endif
  23.  
  24. #ifndef __UCOREUTILITIES__
  25. #include "UCoreUtilities.h"
  26. #endif
  27.  
  28. //    #ifndef __UDISPATCHER__
  29. //    #include "UDispatcher.h"
  30. //    #endif
  31.  
  32. //    #ifndef __UERRORMGR__
  33. //    #include "UErrorMgr.h"
  34. //    #endif
  35.  
  36. #ifndef __UMACAPPGLOBALS__
  37. #include "UMacAppGlobals.h"
  38. #endif
  39.  
  40. #ifndef __UMACAPPUTILITIES__
  41. #include "UMacAppUtilities.h"
  42. #endif
  43.  
  44. // Toolbox
  45.  
  46. #ifndef __AEREGISTRY__
  47. #include <AERegistry.h>
  48. #endif
  49.  
  50. #ifndef __DEVICES__
  51. #include <Devices.h>
  52. #endif
  53.  
  54. #ifndef __ERRORS__
  55. #include <Errors.h>
  56. #endif
  57.  
  58. #ifndef __FILES__
  59. #include <Files.h>
  60. #endif
  61.  
  62. #ifndef __FINDER__
  63. #include <Finder.h>
  64. #endif
  65.  
  66. #ifndef __RESOURCES__
  67. #include <Resources.h>
  68. #endif
  69.  
  70. #ifndef __SCRIPT__
  71. #include <Script.h>
  72. #endif
  73.  
  74. // ANSI
  75.  
  76. #ifndef __STDIO__
  77. #include <stdio.h>
  78. #endif
  79.  
  80. //========================================================================================
  81. // GLOBAL Procedures
  82. //========================================================================================
  83. #undef Inherited
  84.  
  85. //----------------------------------------------------------------------------------------
  86. // NewFile: 
  87. //----------------------------------------------------------------------------------------
  88. #pragma segment MAFileOpen
  89.  
  90. TFile* NewFile(OSType itsFileType,
  91.                   OSType itsCreator,
  92.                   Boolean usesDataFork,
  93.                   ResourceUsage usesRsrcFork,
  94.                   Boolean keepsDataOpen,
  95.                   Boolean keepsRsrcOpen)
  96. {
  97.     TFile * theFile;
  98.  
  99.     theFile = new TFile;
  100.     theFile->IFile(itsFileType, itsCreator, usesDataFork, usesRsrcFork, keepsDataOpen, keepsRsrcOpen);
  101.     return theFile;
  102. } // NewFile 
  103.  
  104.  
  105. //========================================================================================
  106. // CLASS TFile
  107. //========================================================================================
  108. #undef Inherited
  109. #define Inherited TObject
  110.  
  111. #pragma segment MAFileOpen
  112. MA_DEFINE_CLASS_M2(TFile, Inherited, MScriptableObject);
  113.  
  114. //----------------------------------------------------------------------------------------
  115. // TFile constructor
  116. //----------------------------------------------------------------------------------------
  117. #pragma segment MAFileOpen
  118.  
  119. TFile::TFile()
  120.     : MScriptableObject(cFile)
  121. {
  122.     fFileSpec.vRefNum = 0;
  123.     fFileSpec.parID = 0;
  124.     fFileSpec.name[0] = '\0';
  125.  
  126.     fModDate = 0;
  127.     fStationery = FALSE;
  128.     fFileType = kGenericType;
  129.     fCreator = kGenericCreator;
  130.     fScriptTag = smSystemScript;
  131.     fUsesDataFork = FALSE;
  132.     fUsesRsrcFork = noResourceFork;
  133.     fDataPermission = fsRdPerm;
  134.     fRsrcPermission = fsRdPerm;
  135.     fKeepDataOpen = FALSE;
  136.     fKeepRsrcOpen = FALSE;
  137.     fDataRefNum = kNoFileRefnum;
  138.     fRsrcRefNum = kNoFileRefnum;
  139.     fAlias = NULL;
  140. } // TFile::TFile
  141.  
  142. //----------------------------------------------------------------------------------------
  143. // TFile::IFile: 
  144. //----------------------------------------------------------------------------------------
  145. #pragma segment MAFileOpen
  146.  
  147. void TFile::IFile(OSType itsFileType,
  148.                          OSType itsCreator,
  149.                          Boolean usesDataFork,
  150.                          ResourceUsage usesRsrcFork,
  151.                          Boolean keepsDataOpen,
  152.                          Boolean keepsRsrcOpen)
  153. {
  154.     this->IObject();
  155.     
  156. #if qDebugMsg
  157.     if (keepsDataOpen &&!usesDataFork)
  158.     {
  159.         fprintf(stderr, "In TFile::IFile:  keepsDataOpen && !usesDataFork;\n");
  160.         fprintf(stderr, "In TFile::IFile:  usesDataFork = true;\n");
  161.         usesDataFork = TRUE;
  162.     }
  163.     if (keepsRsrcOpen && (usesRsrcFork == noResourceFork))
  164.     {
  165.         fprintf(stderr, "In TFile::IFile:  keepsRsrcOpen && (usesRsrcFork == noResourceFork);\n");
  166.         fprintf(stderr, "In TFile::IFile:  usesRsrcFork = preferResourceFork;\n");
  167.         usesRsrcFork = preferResourceFork;
  168.     }
  169. #endif
  170.  
  171.     fFileType = itsFileType;
  172.     fCreator = itsCreator;
  173.     fUsesDataFork = usesDataFork;
  174.     fUsesRsrcFork = usesRsrcFork;
  175.     fKeepDataOpen = keepsDataOpen;
  176.     fKeepRsrcOpen = keepsRsrcOpen;
  177. } // TFile::IFile 
  178.  
  179. //----------------------------------------------------------------------------------------
  180. // TFile::Free: 
  181. //----------------------------------------------------------------------------------------
  182. #pragma segment MAFileClose
  183.  
  184. TFile::~TFile()
  185. {
  186.     this->CloseFile();
  187.  
  188.     if (fAlias != NULL)
  189.         fAlias = (AliasHandle)DisposeIfHandle((Handle)fAlias);
  190. } // TFile::Free 
  191.  
  192. //----------------------------------------------------------------------------------------
  193. // TFile::Specify: 
  194. //----------------------------------------------------------------------------------------
  195. #pragma segment MAFileNonRes
  196.  
  197. void TFile::Specify(const FSSpec& theFile)
  198. {
  199.     // If we are re-specifying an open file, close the file 
  200.     this->CloseFile();
  201.     fFileSpec = theFile;
  202.  
  203.     if (fAlias != NULL)
  204.         fAlias = (AliasHandle)DisposeIfHandle((Handle)fAlias);
  205.  
  206.     FInfo info;
  207.     OSErr anErr = this->GetFinderInfo(info);
  208.     if (anErr == noErr)
  209.         FailOSErr(NewAliasMinimal(&theFile, &fAlias));
  210.     else if (anErr != fnfErr)
  211.         FailOSErr(anErr);
  212. } // TFile::Specify 
  213.  
  214. //----------------------------------------------------------------------------------------
  215. // TFile::SpecifyWithStandardFileReply: 
  216. //----------------------------------------------------------------------------------------
  217. #pragma segment MAFileNonRes
  218.  
  219. void TFile::SpecifyWithStandardFileReply(const StandardFileReply& itsReply)
  220. {
  221.     this->Specify(itsReply.sfFile);
  222.     
  223.     fFileType = itsReply.sfType;            // only valid for StandardGetFile & CustomGetFile
  224.     fScriptTag = itsReply.sfScript;
  225.     if (itsReply.sfFlags & kIsStationary)    // only valid for StandardGetFile & CustomGetFile
  226.         fStationery = TRUE;
  227. } // TFile::SpecifyWithStandardFileReply 
  228.  
  229. //----------------------------------------------------------------------------------------
  230. // TFile::SpecifyWithSFReply: 
  231. //----------------------------------------------------------------------------------------
  232. #pragma segment MAFileNonRes
  233.  
  234. OSErr TFile::SpecifyWithSFReply(const SFReply& itsReply)
  235. {
  236.     OSErr theErr = this->SpecifyWithTrio(itsReply.vRefNum, 0, itsReply.fName);
  237.     
  238.     fFileType = itsReply.fType;
  239.     return theErr;
  240. } // TFile::SpecifyWithSFReply 
  241.  
  242. //----------------------------------------------------------------------------------------
  243. // TFile::SpecifyWithAlias: 
  244. //----------------------------------------------------------------------------------------
  245. #pragma segment MAFileNonRes
  246.  
  247. OSErr TFile::SpecifyWithAlias(AliasHandle alias)
  248. {
  249.     FSSpec theFileSpec;
  250.     Boolean dontCare;
  251.  
  252.     OSErr theErr = ResolveAlias((FSSpecPtr)NULL, alias, &theFileSpec, &dontCare);
  253.     if (theErr == noErr)
  254.     {
  255.         FInfo finderInfo;
  256.         FXInfo xFinderInfo;
  257.         Boolean isDirectory;
  258.         
  259.         fFileType = kGenericType;        // Since we don't know, set to original values
  260.         fCreator = kGenericCreator;
  261.         fStationery = FALSE;
  262.  
  263.         this->Specify(theFileSpec);
  264.         if (this->GetFinderInfo(finderInfo, xFinderInfo, isDirectory) == noErr)
  265.         {
  266.             if (isDirectory)
  267.             {
  268.                 fFileType = kFolderType;
  269.                 fCreator = kFolderCreator;
  270.             }
  271.             else
  272.             {
  273.                 fFileType = finderInfo.fdType;
  274.                 fCreator = finderInfo.fdCreator;
  275.                 fStationery = ((finderInfo.fdFlags & kIsStationary) != 0);
  276.             }
  277.         }
  278.     }
  279.  
  280.     return theErr;
  281. } // TFile::SpecifyWithAlias 
  282.  
  283. //----------------------------------------------------------------------------------------
  284. // TFile::SpecifyWithFile: 
  285. //----------------------------------------------------------------------------------------
  286. #pragma segment MAFileNonRes
  287.  
  288. void TFile::SpecifyWithFile(TFile* aFile)
  289. {
  290.     aFile->UpdateFileSpec();        // Insure its specs are up-to-date.
  291.     FSSpec theFile = aFile->fFileSpec;
  292.     
  293.     this->Specify(theFile);
  294.     
  295.     fFileType = aFile->fFileType;
  296.     fCreator = aFile->fCreator;
  297.     fScriptTag = aFile->fScriptTag;
  298.     fStationery = aFile->fStationery;
  299. } // TFile::SpecifyWithFile 
  300.  
  301. //----------------------------------------------------------------------------------------
  302. // TFile::SpecifyWithTrio: 
  303. //----------------------------------------------------------------------------------------
  304. #pragma segment MAFileNonRes
  305.  
  306. OSErr TFile::SpecifyWithTrio(short volRefNum,
  307.                                    long dirID,
  308.                                    const CStr63& name)
  309. {
  310.     FSSpec theFileSpec;
  311.     OSErr theErr = noErr;
  312.  
  313.     if ((theErr = FSMakeFSSpec(volRefNum, dirID, name, &theFileSpec)) == fnfErr)
  314.         theErr = noErr;                        // The file may not yet exist
  315.  
  316.     if (theErr == noErr)
  317.         this->Specify(theFileSpec);
  318.     return theErr;
  319. } // TFile::SpecifyWithTrio 
  320.  
  321. //----------------------------------------------------------------------------------------
  322. // TFile::CloseFile: 
  323. //----------------------------------------------------------------------------------------
  324. #pragma segment MAFileClose
  325.  
  326. OSErr TFile::CloseFile()
  327. {
  328.     OSErr dataErr = noErr;
  329.     OSErr rsrcErr = noErr;
  330.  
  331.     if (fUsesDataFork)
  332.         dataErr = this->CloseDataFork();
  333.     if (fUsesRsrcFork != noResourceFork)
  334.     {
  335.         rsrcErr = this->CloseRsrcFork();
  336.         if ((fUsesRsrcFork == preferResourceFork) && (rsrcErr == resFNotFound))
  337.             rsrcErr = noErr;
  338.     }
  339.  
  340.     if (dataErr != noErr)
  341.         return dataErr;
  342.     else
  343.         return rsrcErr;
  344. } // TFile::CloseFile 
  345.  
  346. //----------------------------------------------------------------------------------------
  347. // TFile::CloseFileIfNotKeptOpen: 
  348. //----------------------------------------------------------------------------------------
  349. #pragma segment MAFileClose
  350.  
  351. OSErr TFile::CloseFileIfNotKeptOpen()
  352. {
  353.     OSErr dataErr = noErr;
  354.     OSErr rsrcErr = noErr;
  355.  
  356.     if (fUsesDataFork && !fKeepDataOpen)
  357.         dataErr = this->CloseDataFork();
  358.     if ((fUsesRsrcFork != noResourceFork) && !fKeepRsrcOpen)
  359.     {
  360.         rsrcErr = this->CloseRsrcFork();
  361.         if ((fUsesRsrcFork == preferResourceFork) && (rsrcErr == resFNotFound))
  362.             rsrcErr = noErr;
  363.     }
  364.  
  365.     if (dataErr != noErr)
  366.         return dataErr;
  367.     else
  368.         return rsrcErr;
  369. } // TFile::CloseFileIfNotKeptOpen 
  370.  
  371. //----------------------------------------------------------------------------------------
  372. // TFile::CloseDataFork: 
  373. //----------------------------------------------------------------------------------------
  374. #pragma segment MAFileClose
  375.  
  376. OSErr TFile::CloseDataFork()
  377. {
  378.     OSErr theErr = noErr;
  379.  
  380.     if (fDataRefNum != kNoFileRefnum)
  381.     {
  382.         theErr = FSClose(fDataRefNum);
  383.         fDataRefNum = kNoFileRefnum;
  384.     }
  385.     return theErr;
  386. } // TFile::CloseDataFork 
  387.  
  388. //----------------------------------------------------------------------------------------
  389. // TFile::CloseRsrcFork: 
  390. //----------------------------------------------------------------------------------------
  391. #pragma segment MAFileClose
  392.  
  393. OSErr TFile::CloseRsrcFork()
  394. {
  395.     OSErr theErr = noErr;
  396.  
  397.     if (fRsrcRefNum != kNoFileRefnum)
  398.     {
  399.         CloseResFile(fRsrcRefNum);
  400.         theErr = ResError();
  401.         fRsrcRefNum = kNoFileRefnum;
  402.     }
  403.     return theErr;
  404. } // TFile::CloseRsrcFork 
  405.  
  406. //----------------------------------------------------------------------------------------
  407. // TFile::CreateFile: 
  408. //----------------------------------------------------------------------------------------
  409. #pragma segment MAFileOpen
  410.  
  411. OSErr TFile::CreateFile()
  412. {
  413.     OSErr dataErr = noErr;
  414.     OSErr rsrcErr = noErr;
  415.  
  416.     if (fUsesDataFork)
  417.         dataErr = this->CreateDataFork();
  418.  
  419.     if (fUsesRsrcFork != noResourceFork)
  420.         rsrcErr = this->CreateRsrcFork();
  421.  
  422.     if (dataErr != noErr)
  423.         return dataErr;
  424.     else
  425.         return rsrcErr;
  426. } // TFile::CreateFile 
  427.  
  428. //----------------------------------------------------------------------------------------
  429. // TFile::CreateDataFork: 
  430. //----------------------------------------------------------------------------------------
  431. #pragma segment MAFileOpen
  432.  
  433. OSErr TFile::CreateDataFork()
  434. {
  435.     return FSpCreate(&fFileSpec, fCreator, fFileType, fScriptTag);
  436. } // TFile::CreateDataFork 
  437.  
  438. //----------------------------------------------------------------------------------------
  439. // TFile::CreateRsrcFork: 
  440. //----------------------------------------------------------------------------------------
  441. #pragma segment MAFileOpen
  442.  
  443. OSErr TFile::CreateRsrcFork()
  444. {
  445.     FSpCreateResFile(&fFileSpec, fCreator, fFileType, fScriptTag);
  446.  
  447.     return ResError();
  448. } // TFile::CreateRsrcFork 
  449.  
  450. //----------------------------------------------------------------------------------------
  451. // TFile::DeleteFile: 
  452. //----------------------------------------------------------------------------------------
  453. #pragma segment MAFileClose
  454.  
  455. OSErr TFile::DeleteFile()
  456. {
  457.     fModDate = 0;
  458.     if (fAlias != NULL)
  459.         fAlias = (AliasHandle)DisposeIfHandle((Handle)fAlias);
  460.     
  461.     return FSpDelete(&fFileSpec);
  462. } // TFile::DeleteFile 
  463.  
  464. //----------------------------------------------------------------------------------------
  465. // TFile::OpenFile: 
  466. //----------------------------------------------------------------------------------------
  467. #pragma segment MAFileOpen
  468.  
  469. OSErr TFile::OpenFile()
  470. {
  471.     OSErr dataErr = noErr;
  472.     OSErr rsrcErr = noErr;
  473.  
  474.     if (fUsesDataFork)
  475.         dataErr = this->OpenDataFork(fDataPermission);
  476.  
  477.     if (fUsesRsrcFork != noResourceFork)
  478.     {
  479.         rsrcErr = this->OpenRsrcFork(fRsrcPermission);
  480.         if ((fUsesRsrcFork == preferResourceFork) && (rsrcErr != noErr))
  481.             rsrcErr = noErr;
  482.     }
  483.  
  484.     if (dataErr != noErr)
  485.         return dataErr;
  486.     else
  487.         return rsrcErr;
  488. } // TFile::OpenFile 
  489.  
  490. //----------------------------------------------------------------------------------------
  491. // TFile::OpenFileIfKeptOpen: 
  492. //----------------------------------------------------------------------------------------
  493. #pragma segment MAFileOpen
  494.  
  495. OSErr TFile::OpenFileIfKeptOpen()
  496. {
  497.     OSErr dataErr = noErr;
  498.     OSErr rsrcErr = noErr;
  499.  
  500.     if (fUsesDataFork && fKeepDataOpen)
  501.         dataErr = this->OpenDataFork(fDataPermission);
  502.  
  503.     if ((fUsesRsrcFork != noResourceFork) && fKeepRsrcOpen)
  504.     {
  505.         rsrcErr = this->OpenRsrcFork(fRsrcPermission);
  506.         if ((fUsesRsrcFork == preferResourceFork) && (rsrcErr != noErr))
  507.             rsrcErr = noErr;
  508.     }
  509.  
  510.     if (dataErr != noErr)
  511.         return dataErr;
  512.     else
  513.         return rsrcErr;
  514. } // TFile::OpenFileIfKeptOpen 
  515.  
  516. //----------------------------------------------------------------------------------------
  517. // TFile::OpenDataFork: 
  518. //----------------------------------------------------------------------------------------
  519. #pragma segment MAFileOpen
  520.  
  521. OSErr TFile::OpenDataFork(SignedByte permission)
  522. {
  523.     OSErr theErr = noErr;
  524.  
  525.     if (fDataRefNum == kNoFileRefnum)            // Don't open if already open 
  526.     {
  527.         HParamBlockRec pb;
  528.         CStr63 fileName = fFileSpec.name;
  529.  
  530.         BlockSet((Ptr) & pb, sizeof(HParamBlockRec), 0x00);
  531.         pb.accessParam.ioNamePtr = (StringPtr) fileName;
  532.         pb.accessParam.ioVRefNum = fFileSpec.vRefNum;
  533.         pb.fileParam.ioDirID = fFileSpec.parID;
  534.         
  535.         switch (permission)
  536.         {
  537.             // read/deny write
  538.             case fsRdPerm:
  539.                 pb.accessParam.ioDenyModes = fsRdPerm | 32;
  540.                 break;
  541.  
  542.             // read/write/deny read/deny write            
  543.             case fsWrPerm:
  544.             case fsRdWrPerm:
  545.             case fsCurPerm:
  546.                 pb.accessParam.ioDenyModes = fsRdWrPerm | 16 | 32;
  547.                 break;
  548.             
  549.             // read/write/deny none
  550.             case fsRdWrShPerm:
  551.                 pb.accessParam.ioDenyModes = fsRdWrPerm;
  552.                 break;
  553.     
  554.             // read/deny write            
  555.             default:
  556.                 pb.accessParam.ioDenyModes = fsRdPerm | 32;
  557.         }
  558.                 
  559.         theErr = PBHOpenDenySync(&pb);            // Try the shared volume open. 
  560.  
  561.         if ((theErr == paramErr) || (theErr == wPrErr))    // Not on a shared volume, try HFS open. 
  562.         {
  563.             pb.ioParam.ioPermssn = permission & 3;
  564.             theErr = PBHOpenSync(&pb);
  565.         }
  566.  
  567.         if (theErr == noErr)
  568.             fDataRefNum = pb.ioParam.ioRefNum;
  569.     }
  570.  
  571.     return theErr;
  572. } // TFile::OpenDataFork 
  573.  
  574. //----------------------------------------------------------------------------------------
  575. // TFile::OpenRsrcFork: 
  576. //----------------------------------------------------------------------------------------
  577. #pragma segment MAFileOpen
  578.  
  579. OSErr TFile::OpenRsrcFork(SignedByte permission)
  580. {
  581.     OSErr theErr = noErr;
  582.  
  583.     if (fRsrcRefNum == kNoFileRefnum)            // Don't open if already open 
  584.     {
  585.         fRsrcRefNum = FSpOpenResFile(&fFileSpec, (permission & 7));
  586.         theErr = ResError();
  587.     }
  588.     if (theErr != noErr)
  589.         fRsrcRefNum = kNoFileRefnum;
  590.     return theErr;
  591. } // TFile::OpenRsrcFork 
  592.  
  593. //----------------------------------------------------------------------------------------
  594. // TFile::ExchangeFiles: 
  595. //----------------------------------------------------------------------------------------
  596. #pragma segment MAFileWrite
  597.  
  598. OSErr TFile::ExchangeFiles(TFile* aFile)
  599. {
  600.     return FSpExchangeFiles(&fFileSpec, &aFile->fFileSpec);
  601. } // TFile::ExchangeFiles 
  602.  
  603. //----------------------------------------------------------------------------------------
  604. // TFile::GetAlias: 
  605. //----------------------------------------------------------------------------------------
  606. #pragma segment MAFileNonRes
  607.  
  608. OSErr TFile::GetAlias(AliasHandle& alias)
  609. {
  610.     return NewAliasMinimal(&fFileSpec, &alias);
  611. } // TFile::GetAlias 
  612.  
  613. //----------------------------------------------------------------------------------------
  614. // TFile::GetCatInfo: 
  615. //----------------------------------------------------------------------------------------
  616. #pragma segment MAFileNonRes
  617.  
  618. OSErr TFile::GetCatInfo(CInfoPBRec& cInfo)
  619. {
  620.     CStr63 itsName;
  621.  
  622.     itsName = fFileSpec.name;
  623.     cInfo.hFileInfo.ioNamePtr = (StringPtr) itsName;
  624.     cInfo.hFileInfo.ioVRefNum = fFileSpec.vRefNum;
  625.     cInfo.hFileInfo.ioFDirIndex = 0;
  626.     cInfo.hFileInfo.ioDirID = fFileSpec.parID;
  627.     OSErr err = PBGetCatInfoSync(&cInfo);
  628.     cInfo.hFileInfo.ioNamePtr = NULL;
  629.     return err;
  630. } // TFile::GetCatInfo 
  631.  
  632. //----------------------------------------------------------------------------------------
  633. // TFile::GetCreationDate: 
  634. //----------------------------------------------------------------------------------------
  635. #pragma segment MAFileNonRes
  636.  
  637. long TFile::GetCreationDate()
  638. {
  639.     long returnVal = 0;
  640.  
  641.     CInfoPBRec cInfo;
  642.  
  643.     BlockSet((Ptr) & cInfo, sizeof(CInfoPBRec), 0x00);// zero-out our storage 
  644.     if (this->GetCatInfo(cInfo) == noErr)
  645.     {
  646.         Boolean isDirectory = ((cInfo.hFileInfo.ioFlAttrib & ioDirMask) != 0);
  647.         if (isDirectory)
  648.             returnVal = cInfo.dirInfo.ioDrCrDat;
  649.         else
  650.             returnVal = cInfo.hFileInfo.ioFlCrDat;
  651.     }
  652.  
  653.     return returnVal;
  654. } // TFile::GetCreationDate 
  655.  
  656. //----------------------------------------------------------------------------------------
  657. // TFile::GetDataLength: 
  658. //----------------------------------------------------------------------------------------
  659. #pragma segment MAFileRead
  660.  
  661. OSErr TFile::GetDataLength(long& length)
  662. {
  663.     return GetEOF(fDataRefNum, &length);
  664. } // TFile::GetDataLength 
  665.  
  666. //----------------------------------------------------------------------------------------
  667. // TFile::GetDataMark: 
  668. //----------------------------------------------------------------------------------------
  669. #pragma segment MAFileRead
  670.  
  671. OSErr TFile::GetDataMark(long& mark)
  672. {
  673.     return GetFPos(fDataRefNum, &mark);
  674. } // TFile::GetDataMark 
  675.  
  676. //----------------------------------------------------------------------------------------
  677. // TFile::GetDirID: 
  678. //----------------------------------------------------------------------------------------
  679. #pragma segment MAFileRes
  680.  
  681. long TFile::GetDirID()
  682. {
  683.     return fFileSpec.parID;
  684. } // TFile::GetDirID 
  685.  
  686. //----------------------------------------------------------------------------------------
  687. // TFile::GetFileCreator: 
  688. //----------------------------------------------------------------------------------------
  689. #pragma segment MAFileNonRes
  690.  
  691. OSErr TFile::GetFileCreator(OSType& creator)
  692. {
  693.     FInfo finderInfo;
  694.     FXInfo xFinderInfo;
  695.     Boolean isDirectory;
  696.     
  697.     OSErr theErr = this->GetFinderInfo(finderInfo, xFinderInfo, isDirectory);
  698.     if (theErr == noErr)
  699.     {
  700.         if (isDirectory)
  701.             creator = kFolderCreator;
  702.         else
  703.             creator = finderInfo.fdCreator;
  704.     }
  705.     else
  706.         creator = kGenericCreator;
  707.     
  708.     return theErr;
  709. } // TFile::GetFileCreator 
  710.  
  711. //----------------------------------------------------------------------------------------
  712. // TFile::GetFileInfo: 
  713. //----------------------------------------------------------------------------------------
  714. #pragma segment MAFileNonRes
  715.  
  716. OSErr TFile::GetFileInfo(HParamBlockRec& pb)
  717. {
  718.     CStr63 itsName;
  719.  
  720.     itsName = fFileSpec.name;
  721.     pb.fileParam.ioNamePtr = (StringPtr) itsName;
  722.     pb.fileParam.ioVRefNum = fFileSpec.vRefNum;
  723.     pb.fileParam.ioDirID = fFileSpec.parID;
  724.     pb.fileParam.ioFVersNum = 0;
  725.     pb.fileParam.ioFDirIndex = 0;
  726.     OSErr err = PBHGetFInfoSync(&pb);
  727.     pb.fileParam.ioNamePtr = NULL;
  728.     return err;
  729. } // TFile::GetFileInfo 
  730.  
  731. //----------------------------------------------------------------------------------------
  732. // TFile::GetFileType: 
  733. //----------------------------------------------------------------------------------------
  734. #pragma segment MAFileNonRes
  735.  
  736. OSErr TFile::GetFileType(OSType& fileType)
  737. {
  738.     FInfo finderInfo;
  739.     FXInfo xFinderInfo;
  740.     Boolean isDirectory;
  741.     
  742.     OSErr theErr = this->GetFinderInfo(finderInfo, xFinderInfo, isDirectory);
  743.     if (theErr == noErr)
  744.     {
  745.         if (isDirectory)
  746.             fileType = kFolderType;
  747.         else
  748.             fileType = finderInfo.fdType;
  749.     }
  750.     else
  751.         fileType = '\?\?\?\?';
  752.     
  753.     return theErr;
  754. } // TFile::GetFileType 
  755.  
  756. //----------------------------------------------------------------------------------------
  757. // TFile::GetFileSpec: 
  758. //----------------------------------------------------------------------------------------
  759. #pragma segment MAFileRes
  760.  
  761. void TFile::GetFileSpec(FSSpec& theFileSpec)
  762. {
  763.     theFileSpec = fFileSpec;
  764. } // TFile::GetFileSpec 
  765.  
  766. //----------------------------------------------------------------------------------------
  767. // TFile::GetFinderInfo: 
  768. //----------------------------------------------------------------------------------------
  769. #pragma segment MAFileNonRes
  770.  
  771. OSErr TFile::GetFinderInfo(FInfo& fndrInfo)
  772. {
  773. #if 0
  774.     return FSpGetFInfo(&fFileSpec, &fndrInfo);
  775. #else
  776.     FXInfo itsFXInfo;
  777.     Boolean isDirectory;
  778.     return GetFinderInfo(fndrInfo, itsFXInfo, isDirectory);
  779. #endif
  780. } // TFile::GetFinderInfo 
  781.  
  782. //----------------------------------------------------------------------------------------
  783. // TFile::GetFinderInfo: 
  784. //----------------------------------------------------------------------------------------
  785. #pragma segment MAFileNonRes
  786.  
  787. OSErr TFile::GetFinderInfo(FInfo& fndrInfo, FXInfo& itsFXInfo, Boolean& isDirectory)
  788. {
  789.     CInfoPBRec cInfo;
  790.  
  791.     BlockSet((Ptr) & cInfo, sizeof(CInfoPBRec), 0x00);// zero-out our storage 
  792.     cInfo.hFileInfo.ioCompletion = NULL;
  793.     cInfo.hFileInfo.ioNamePtr = (unsigned char*)&fFileSpec.name;
  794.     cInfo.hFileInfo.ioVRefNum = fFileSpec.vRefNum;
  795.     cInfo.hFileInfo.ioFDirIndex = 0;
  796.     cInfo.hFileInfo.ioDirID = fFileSpec.parID;
  797.  
  798.     PBGetCatInfoSync(&cInfo);
  799.     
  800.     if (cInfo.hFileInfo.ioResult == noErr)
  801.     {
  802.         isDirectory = ((cInfo.hFileInfo.ioFlAttrib & ioDirMask) != 0);
  803.         if (isDirectory)
  804.         {
  805.             fndrInfo = *(FInfo*)&cInfo.dirInfo.ioDrUsrWds;
  806.             itsFXInfo = *(FXInfo*)&cInfo.dirInfo.ioDrFndrInfo;
  807.         }
  808.         else
  809.         {
  810.             fndrInfo = cInfo.hFileInfo.ioFlFndrInfo;
  811.             itsFXInfo = cInfo.hFileInfo.ioFlXFndrInfo;
  812.         }
  813.     }
  814.  
  815.     return cInfo.hFileInfo.ioResult;
  816. } // TFile::GetFinderInfo 
  817.  
  818. //----------------------------------------------------------------------------------------
  819. // TFile::GetModificationDate: 
  820. //----------------------------------------------------------------------------------------
  821. #pragma segment MAFileNonRes
  822.  
  823. long TFile::GetModificationDate()
  824. {
  825.     long returnVal = 0;
  826.  
  827.     CInfoPBRec cInfo;
  828.  
  829.     BlockSet((Ptr) & cInfo, sizeof(CInfoPBRec), 0x00);// zero-out our storage 
  830.     if (this->GetCatInfo(cInfo) == noErr)
  831.     {
  832.         Boolean isDirectory = ((cInfo.hFileInfo.ioFlAttrib & ioDirMask) != 0);
  833.         if (isDirectory)
  834.             returnVal = cInfo.dirInfo.ioDrMdDat;
  835.         else
  836.             returnVal = cInfo.hFileInfo.ioFlMdDat;
  837.     }
  838.  
  839.     return returnVal;
  840. } // TFile::GetModificationDate 
  841.  
  842. //----------------------------------------------------------------------------------------
  843. // TFile::GetName: 
  844. //----------------------------------------------------------------------------------------
  845. #pragma segment MAFileRes
  846.  
  847. void TFile::GetName(CStr63& name)
  848. {
  849.     name = fFileSpec.name;
  850. } // TFile::GetName 
  851.  
  852. //----------------------------------------------------------------------------------------
  853. // TFile::GetPathName: 
  854. //----------------------------------------------------------------------------------------
  855. #pragma segment MAFileWrite
  856.  
  857. OSErr TFile::GetPathName(CStr255& pathName)
  858. {
  859.     CStr63 dirName;
  860.     
  861.     pathName.Empty();
  862.     
  863.     CStr2 delimiter = HasAUX() ? "/" : ":";
  864.     
  865.     CInfoPBRec cInfoPB;
  866.     cInfoPB.dirInfo.ioFDirIndex = -1;
  867.     cInfoPB.dirInfo.ioVRefNum = fFileSpec.vRefNum;
  868.     cInfoPB.dirInfo.ioDrDirID = fFileSpec.parID;
  869.     cInfoPB.dirInfo.ioNamePtr = (StringPtr) dirName;
  870.     
  871.     OSErr err = noErr;
  872.     while (err == noErr)
  873.     {
  874.         err = PBGetCatInfoSync(&cInfoPB);
  875.         pathName.Insert(dirName + delimiter, 1);
  876.         if (cInfoPB.dirInfo.ioDrDirID == fsRtDirID)
  877.             break;
  878.  
  879.         cInfoPB.dirInfo.ioDrDirID = cInfoPB.dirInfo.ioDrParID;
  880.     }
  881.     
  882.     if (HasAUX())
  883.         pathName.Insert("/", 1);
  884.     
  885.     return err;
  886.     
  887. } // TFile::GetPathName 
  888.  
  889. //----------------------------------------------------------------------------------------
  890. // TFile::GetPhysicalSize: 
  891. //----------------------------------------------------------------------------------------
  892. #pragma segment MAFileWrite
  893.  
  894. OSErr TFile::GetPhysicalSize(long& dataSize,
  895.                                     long& rsrcSize)
  896. {
  897.     HParamBlockRec pb;
  898.     OSErr theErr;
  899.  
  900.     if ((theErr = this->GetFileInfo(pb)) == noErr)
  901.     {
  902.         dataSize = pb.fileParam.ioFlPyLen;
  903.         rsrcSize = pb.fileParam.ioFlRPyLen;
  904.     }
  905.     return theErr;
  906. } // TFile::GetPhysicalSize 
  907.  
  908. //----------------------------------------------------------------------------------------
  909. // TFile::GetScript: 
  910. //----------------------------------------------------------------------------------------
  911. #pragma segment MAFileNonRes
  912.  
  913. OSErr TFile::GetScript(ScriptCode& theScript)
  914. {
  915.     OSErr theErr;
  916.     CInfoPBRec cInfo;
  917.  
  918.     BlockSet((Ptr) & cInfo, sizeof(CInfoPBRec), 0x00);// zero-out our storage 
  919.     theErr = this->GetCatInfo(cInfo);
  920.     if (theErr == noErr)
  921.     {
  922.         theScript = cInfo.hFileInfo.ioFlXFndrInfo.fdScript;
  923.         fScriptTag = theScript;
  924.     }
  925.     return theErr;
  926. } // TFile::GetScript 
  927.  
  928. //----------------------------------------------------------------------------------------
  929. // TFile::SetModificationDate: 
  930. //----------------------------------------------------------------------------------------
  931. #pragma segment MAFileNonRes
  932.  
  933. OSErr TFile::SetModificationDate(long modificationDate)
  934. {
  935.     // Get the current information and just touch the modification date
  936.     CInfoPBRec cInfo;
  937.     OSErr theErr = noErr;
  938.  
  939.     BlockSet((Ptr) & cInfo, sizeof(CInfoPBRec), 0x00);// zero-out our storage 
  940.     if (this->GetCatInfo(cInfo) == noErr)
  941.     {
  942.         Boolean isDirectory = ((cInfo.hFileInfo.ioFlAttrib & ioDirMask) != 0);
  943.         if (isDirectory)
  944.             cInfo.dirInfo.ioDrMdDat = modificationDate;
  945.         else
  946.             cInfo.hFileInfo.ioFlMdDat = modificationDate;
  947.  
  948.         this->SetCatInfo(cInfo);
  949.     }
  950.  
  951.     return theErr;
  952. } // TFile::SetModificationDate 
  953.         
  954. //----------------------------------------------------------------------------------------
  955. // TFile::SetCreationDate: 
  956. //----------------------------------------------------------------------------------------
  957. #pragma segment MAFileNonRes
  958.  
  959. OSErr TFile::SetCreationDate(long creationDate)
  960. {
  961.     // Get the current information and just touch the modification date
  962.     CInfoPBRec cInfo;
  963.     OSErr theErr = noErr;
  964.  
  965.     BlockSet((Ptr) & cInfo, sizeof(CInfoPBRec), 0x00);// zero-out our storage 
  966.     if (this->GetCatInfo(cInfo) == noErr)
  967.     {
  968.         Boolean isDirectory = ((cInfo.hFileInfo.ioFlAttrib & ioDirMask) != 0);
  969.         if (isDirectory)
  970.             cInfo.dirInfo.ioDrCrDat = creationDate;
  971.         else
  972.             cInfo.hFileInfo.ioFlCrDat = creationDate;
  973.  
  974.         this->SetCatInfo(cInfo);
  975.     }
  976.  
  977.     return theErr;
  978. } // TFile::SetCreationDate 
  979.  
  980. //----------------------------------------------------------------------------------------
  981. // TFile::SetFinderInfo: 
  982. //----------------------------------------------------------------------------------------
  983. #pragma segment MAFileNonRes
  984.  
  985. OSErr TFile::SetFinderInfo(const FInfo& fndrInfo)
  986. {
  987.     HParamBlockRec pb;
  988.     OSErr theErr = noErr;
  989.  
  990.     // Get the current information and just touch the finder info
  991.     theErr = this->GetFileInfo(pb);
  992.     if (theErr == noErr)
  993.     {
  994.         pb.fileParam.ioFlFndrInfo = fndrInfo;
  995.         theErr = this->SetFileInfo(pb);
  996.     }
  997.     return theErr;
  998. } // TFile::SetFinderInfo 
  999.  
  1000. //----------------------------------------------------------------------------------------
  1001. // TFile::FlushVolume: 
  1002. //----------------------------------------------------------------------------------------
  1003. #pragma segment MAFileWrite
  1004.  
  1005. OSErr TFile::FlushVolume()
  1006. {
  1007.     return FlushVol(NULL, fFileSpec.vRefNum);
  1008. } // TFile::FlushVolume 
  1009.  
  1010. //----------------------------------------------------------------------------------------
  1011. // TFile::GetBlockSize: 
  1012. //----------------------------------------------------------------------------------------
  1013. #pragma segment MAFileWrite
  1014.  
  1015. OSErr TFile::GetBlockSize(long& blockSize)
  1016. {
  1017.     HParamBlockRec pb;
  1018.     OSErr theErr;
  1019.  
  1020.     BlockSet((Ptr) & pb, sizeof(HParamBlockRec), 0x00);// zero-out our storage 
  1021.     theErr = this->GetVolumeInfo(pb);
  1022.     if (theErr == noErr)
  1023.         blockSize = pb.volumeParam.ioVAlBlkSiz;
  1024.     else
  1025.         blockSize = 0;
  1026.     return theErr;
  1027. } // TFile::GetBlockSize 
  1028.  
  1029. //----------------------------------------------------------------------------------------
  1030. // TFile::GetFreeBlocks: 
  1031. //----------------------------------------------------------------------------------------
  1032. #pragma segment MAFileWrite
  1033.  
  1034. OSErr TFile::GetFreeBlocks(long& freeBlocks)
  1035. {
  1036.     HParamBlockRec pb;
  1037.     OSErr theErr;
  1038.  
  1039.  
  1040.     BlockSet((Ptr) & pb, sizeof(HParamBlockRec), 0x00);// zero-out our storage 
  1041.     theErr = this->GetVolumeInfo(pb);
  1042.     if (theErr == noErr)
  1043.         freeBlocks = pb.volumeParam.ioVFrBlk;
  1044.     else
  1045.         freeBlocks = 0;
  1046.     return theErr;
  1047. } // TFile::GetFreeBlocks 
  1048.  
  1049. //----------------------------------------------------------------------------------------
  1050. // TFile::GetVolumeInfo: 
  1051. //----------------------------------------------------------------------------------------
  1052. #pragma segment MAFileWrite
  1053.  
  1054. OSErr TFile::GetVolumeInfo(HParamBlockRec& pb)
  1055. {
  1056.     pb.volumeParam.ioCompletion = NULL;
  1057.     pb.volumeParam.ioNamePtr = NULL;
  1058.     pb.volumeParam.ioVRefNum = fFileSpec.vRefNum;
  1059.     pb.volumeParam.ioVolIndex = -1;                // Use the vRefNum since it is all we have 
  1060.     return PBHGetVInfoSync(&pb);
  1061. } // TFile::GetVolumeInfo 
  1062.  
  1063. //----------------------------------------------------------------------------------------
  1064. // TFile::GetVolumeName: 
  1065. //----------------------------------------------------------------------------------------
  1066. #pragma segment MAFileNonRes
  1067.  
  1068. OSErr TFile::GetVolumeName(CStr63& name)
  1069. {
  1070.     HParamBlockRec pb;
  1071.  
  1072.     BlockSet((Ptr) & pb, sizeof(HParamBlockRec), 0x00);
  1073.     pb.volumeParam.ioNamePtr = (StringPtr) name;            // Fill in the name 
  1074.     pb.volumeParam.ioVRefNum = fFileSpec.vRefNum;
  1075.     pb.volumeParam.ioVolIndex = 0;                // Use the vRefNum since it is all we have 
  1076.     return PBHGetVInfoSync(&pb);
  1077. } // TFile::GetVolumeName 
  1078.  
  1079. //----------------------------------------------------------------------------------------
  1080. // TFile::GetVolRefNum: 
  1081. //----------------------------------------------------------------------------------------
  1082. #pragma segment MAFileOpen
  1083.  
  1084. short TFile::GetVolRefNum()
  1085. {
  1086.     return fFileSpec.vRefNum;
  1087. } // TFile::GetVolRefNum 
  1088.  
  1089. //----------------------------------------------------------------------------------------
  1090. // TFile::IsDataForkOpen: 
  1091. //----------------------------------------------------------------------------------------
  1092. #pragma segment MAFileOpen
  1093.  
  1094. Boolean TFile::IsDataForkOpen()
  1095. {
  1096.     return (fDataRefNum != kNoFileRefnum);
  1097. } // TFile::IsDataForkOpen 
  1098.  
  1099. //----------------------------------------------------------------------------------------
  1100. // TFile::IsRsrcForkOpen: 
  1101. //----------------------------------------------------------------------------------------
  1102. #pragma segment MAFileOpen
  1103.  
  1104. Boolean TFile::IsRsrcForkOpen()
  1105. {
  1106.     return (fRsrcRefNum != kNoFileRefnum);
  1107. } // TFile::IsRsrcForkOpen 
  1108.  
  1109. //----------------------------------------------------------------------------------------
  1110. // TFile::IsSameFile: 
  1111. //----------------------------------------------------------------------------------------
  1112. #pragma segment MAFileOpen
  1113.  
  1114. Boolean TFile::IsSameFile(TFile* aFile)
  1115. {
  1116.     // See if aFile represents the same file as this.
  1117.     this->UpdateFileSpec();        // Make sure we're up-to-date.
  1118.  
  1119.  
  1120.     if ((fFileSpec.vRefNum == aFile->GetVolRefNum())
  1121.         && (fFileSpec.parID == aFile->GetDirID()))
  1122.     {
  1123.         CStr63        name;
  1124.         
  1125.         aFile->GetName(name);
  1126.         return (EqualString(*((CString *) fFileSpec.name), name, FALSE, TRUE));
  1127.     }
  1128.     return FALSE;
  1129. } // TFile::IsSameFile 
  1130.  
  1131. //----------------------------------------------------------------------------------------
  1132. // TFile::IsStationery: 
  1133. //----------------------------------------------------------------------------------------
  1134. #pragma segment MAFileOpen
  1135.  
  1136. Boolean TFile::IsStationery()
  1137. {
  1138.     return fStationery;
  1139. } // TFile::IsStationery 
  1140.  
  1141. //----------------------------------------------------------------------------------------
  1142. // TFile::IsModified: 
  1143. //----------------------------------------------------------------------------------------
  1144. #pragma segment MAFileNonRes
  1145.  
  1146. Boolean TFile::IsModified()
  1147. {
  1148.     long theDate;
  1149.  
  1150.     theDate = this->GetModificationDate();
  1151.     if (theDate != fModDate)
  1152.         return TRUE;
  1153.     else
  1154.         return FALSE;
  1155. } // TFile::IsModified 
  1156.  
  1157. //----------------------------------------------------------------------------------------
  1158. // TFile::IsVolumeLocked: 
  1159. //----------------------------------------------------------------------------------------
  1160. #pragma segment MAFileNonRes
  1161.  
  1162. OSErr TFile::IsVolumeLocked(Boolean& locked)
  1163. {
  1164.     HParamBlockRec pb;
  1165.     OSErr theErr;
  1166.  
  1167.     if ((theErr = this->GetVolumeInfo(pb)) == noErr)
  1168.         locked = ((pb.volumeParam.ioVAtrb & 0x8080) != 0);
  1169.     return theErr;
  1170. } // TFile::IsVolumeLocked 
  1171.  
  1172. //----------------------------------------------------------------------------------------
  1173. // TFile::HasDataFork: 
  1174. //----------------------------------------------------------------------------------------
  1175. #pragma segment MAFileNonRes
  1176.  
  1177. Boolean TFile::HasDataFork()
  1178. {
  1179.     return fUsesDataFork;
  1180. } // TFile::HasDataFork 
  1181.  
  1182. //----------------------------------------------------------------------------------------
  1183. // TFile::HasRsrcFork: 
  1184. //----------------------------------------------------------------------------------------
  1185. #pragma segment MAFileRes
  1186.  
  1187. Boolean TFile::HasRsrcFork()
  1188. {
  1189.     return (fUsesRsrcFork != noResourceFork);
  1190. } // TFile::HasRsrcFork 
  1191.  
  1192. //----------------------------------------------------------------------------------------
  1193. // TFile::HasValidFileSpec: 
  1194. //----------------------------------------------------------------------------------------
  1195. #pragma segment MAFileNonRes
  1196.  
  1197. Boolean TFile::HasValidFileSpec()
  1198. {
  1199.     return ((fFileSpec.vRefNum != 0) || (fFileSpec.parID != 0));
  1200. } // TFile::HasValidFileSpec 
  1201.  
  1202. //----------------------------------------------------------------------------------------
  1203. // TFile::Modified: 
  1204. //----------------------------------------------------------------------------------------
  1205. #pragma segment MAFileNonRes
  1206.  
  1207. void TFile::Modified()
  1208. {
  1209.     fModDate = this->GetModificationDate();
  1210.     
  1211.     FInfo info;
  1212.     FailOSErr(this->GetFinderInfo(info));
  1213.  
  1214.     if (fAlias != NULL)
  1215.         fAlias = (AliasHandle)DisposeIfHandle((Handle)fAlias);
  1216.     FailOSErr(NewAliasMinimal(&fFileSpec, &fAlias));
  1217. } // TFile::Modified 
  1218.  
  1219. //----------------------------------------------------------------------------------------
  1220. // TFile::MoveAndRename: 
  1221. //----------------------------------------------------------------------------------------
  1222. #pragma segment MAFileWrite
  1223.  
  1224. OSErr TFile::MoveAndRename(const FSSpec& dest)
  1225. {
  1226.     CInfoPBRec cInfoPB;
  1227.     CMovePBRec cMovePB;
  1228.     CStr255 sourceName;                    // needs to be CStr255 for call to HRename
  1229.     CStr63 destName;
  1230.     long parentDirID;
  1231.     OSErr theErr;
  1232.  
  1233.     cInfoPB.dirInfo.ioVRefNum = dest.vRefNum;
  1234.     cInfoPB.dirInfo.ioDrDirID = dest.parID;
  1235.     cInfoPB.dirInfo.ioNamePtr = (StringPtr) destName;        // Will be filled in 
  1236.     cInfoPB.dirInfo.ioFDirIndex = -1;
  1237.     if ((theErr = PBGetCatInfoSync(&cInfoPB)) != noErr)
  1238.         return theErr;
  1239.     parentDirID = cInfoPB.dirInfo.ioDrParID;
  1240.  
  1241.     sourceName = fFileSpec.name;
  1242.     cMovePB.ioVRefNum = fFileSpec.vRefNum;
  1243.     cMovePB.ioDirID = fFileSpec.parID;
  1244.     cMovePB.ioNamePtr = (StringPtr) sourceName;
  1245.     cMovePB.ioNewDirID = parentDirID;
  1246.     cMovePB.ioNewName = (StringPtr) destName;
  1247.     if ((theErr = PBCatMoveSync(&cMovePB)) != noErr)
  1248.         return theErr;
  1249.     return HRename(dest.vRefNum, dest.parID, sourceName, (const CStr255&) dest.name);
  1250. } // TFile::MoveAndRename 
  1251.  
  1252. //----------------------------------------------------------------------------------------
  1253. // TFile::ReadData: 
  1254. //----------------------------------------------------------------------------------------
  1255. #pragma segment MAFileRead
  1256.  
  1257. OSErr TFile::ReadData(void* buffer,
  1258.                              long& count)
  1259. {
  1260.     return FSRead(fDataRefNum, &count, (Ptr)buffer);
  1261. } // TFile::ReadData 
  1262.  
  1263. //----------------------------------------------------------------------------------------
  1264. // TFile::ReadUntil: 
  1265. //----------------------------------------------------------------------------------------
  1266. #pragma segment MAFileRead
  1267.  
  1268. OSErr TFile::ReadUntil(void* buffer,
  1269.                                  long& count,
  1270.                                  char untilChar)
  1271. {
  1272.    ParamBlockRec    theParamBlock;
  1273.    OSErr    theResult;
  1274.  
  1275.      if (fDataRefNum != kNoFileRefnum)
  1276.     {
  1277.         theParamBlock.ioParam.ioCompletion = NULL;
  1278.         theParamBlock.ioParam.ioRefNum = fDataRefNum;
  1279.         theParamBlock.ioParam.ioBuffer = (Ptr) buffer;
  1280.         theParamBlock.ioParam.ioReqCount = count;
  1281.         theParamBlock.ioParam.ioPosMode = fsAtMark | 0x0080 | (untilChar * 0x100);
  1282.         theResult = PBReadSync(&theParamBlock);
  1283.         count = theParamBlock.ioParam.ioActCount;
  1284.         return theResult;
  1285.     }
  1286.     else
  1287.         return noErr;
  1288.  } // TFile::ReadUnti
  1289.  
  1290. //----------------------------------------------------------------------------------------
  1291. // TFile::RenameFile: 
  1292. //----------------------------------------------------------------------------------------
  1293. #pragma segment MAFileWrite
  1294.  
  1295. OSErr TFile::RenameFile(const CStr63& newName)
  1296. {
  1297.     return FSpRename(&fFileSpec, (ConstStr255Param)&newName);
  1298. } // TFile::RenameFile 
  1299.  
  1300. //----------------------------------------------------------------------------------------
  1301. // TFile::SetCatInfo: 
  1302. //----------------------------------------------------------------------------------------
  1303. #pragma segment MAFileWrite
  1304.  
  1305. OSErr TFile::SetCatInfo(CInfoPBRec& cInfo)
  1306. {
  1307.     CStr63 fileName = fFileSpec.name;
  1308.  
  1309.     cInfo.hFileInfo.ioCompletion = NULL;
  1310.     cInfo.hFileInfo.ioNamePtr = (StringPtr) fileName;
  1311.     cInfo.hFileInfo.ioVRefNum = fFileSpec.vRefNum;
  1312.     cInfo.hFileInfo.ioDirID = fFileSpec.parID;
  1313.     OSErr err = PBSetCatInfoSync((CInfoPBRec*) &cInfo);
  1314.     cInfo.hFileInfo.ioNamePtr = NULL;
  1315.     return err;
  1316. } // TFile::SetCatInfo 
  1317.  
  1318. //----------------------------------------------------------------------------------------
  1319. // TFile::SetDataLength: 
  1320. //----------------------------------------------------------------------------------------
  1321. #pragma segment MAFileWrite
  1322.  
  1323. OSErr TFile::SetDataLength(long length)
  1324. {
  1325.     return SetEOF(fDataRefNum, length);
  1326. } // TFile::SetDataLength 
  1327.  
  1328. //----------------------------------------------------------------------------------------
  1329. // TFile::SetDataMark: 
  1330. //----------------------------------------------------------------------------------------
  1331. #pragma segment MAFileWrite
  1332.  
  1333. OSErr TFile::SetDataMark(long mark,
  1334.                                 short fromWhere)
  1335. {
  1336.     return SetFPos(fDataRefNum, fromWhere, mark);
  1337. } // TFile::SetDataMark 
  1338.  
  1339. //----------------------------------------------------------------------------------------
  1340. // TFile::SetFileInfo: 
  1341. //----------------------------------------------------------------------------------------
  1342. #pragma segment MAFileNonRes
  1343.  
  1344. OSErr TFile::SetFileInfo(HParamBlockRec& pb)
  1345. {
  1346.     CStr63 fileName = fFileSpec.name;
  1347.  
  1348.     pb.fileParam.ioNamePtr = (StringPtr) fileName;
  1349.     pb.fileParam.ioVRefNum = fFileSpec.vRefNum;
  1350.     pb.fileParam.ioDirID = fFileSpec.parID;
  1351.     OSErr err = PBHSetFInfoSync((HParamBlockRec*) &pb);
  1352.     pb.fileParam.ioNamePtr = NULL;
  1353.     return err;
  1354. } // TFile::SetFileInfo 
  1355.  
  1356. //----------------------------------------------------------------------------------------
  1357. // TFile::SetName: 
  1358. //----------------------------------------------------------------------------------------
  1359. #pragma segment MAFileRes
  1360.  
  1361. void TFile::SetName(const CStr63& newName)
  1362. {
  1363.     newName.CopyTo(fFileSpec.name);
  1364. } // TFile::SetName 
  1365.  
  1366. //----------------------------------------------------------------------------------------
  1367. // TFile::SetScript: 
  1368. //----------------------------------------------------------------------------------------
  1369. #pragma segment MAFileWrite
  1370.  
  1371. OSErr TFile::SetScript(ScriptCode theScript)
  1372. {
  1373.     OSErr theErr;
  1374.     CInfoPBRec cInfo;
  1375.  
  1376.     // Get the current info so we don't have to set up the entire record 
  1377.     if ((theErr = this->GetCatInfo(cInfo)) == noErr)
  1378.     {
  1379.         cInfo.hFileInfo.ioFlXFndrInfo.fdScript = theScript;
  1380.         theErr = this->SetCatInfo(cInfo);
  1381.     }
  1382.     return theErr;
  1383. } // TFile::SetScript 
  1384.  
  1385. //----------------------------------------------------------------------------------------
  1386. // TFile::SetPermissions: 
  1387. //----------------------------------------------------------------------------------------
  1388. #pragma segment MAFileWrite
  1389.  
  1390. void TFile::SetPermissions(SignedByte dataPermission,
  1391.                                   SignedByte rsrcPermission)
  1392. {
  1393.     fDataPermission = dataPermission;
  1394.     fRsrcPermission = rsrcPermission;
  1395. } // TFile::SetPermissions 
  1396.  
  1397. //----------------------------------------------------------------------------------------
  1398. // TFile::UpdateFileSpec: 
  1399. //----------------------------------------------------------------------------------------
  1400. #pragma segment MAFileWrite
  1401.  
  1402. Boolean TFile::UpdateFileSpec()
  1403. {
  1404.     // Before we go using the aFile's information we must make sure it's
  1405.     // up-to-date (things might have change in the Finder, for example, such
  1406.     // as moving the file to another folder on the same volume or renaming
  1407.     // the file.
  1408.     
  1409.     Boolean        wasChanged = FALSE;
  1410.     
  1411.     if (fAlias != NULL)
  1412.     {
  1413.         // We can't just fail if no interaction is allowed before resolving the alias
  1414.         // because there may be no need for user interaction.
  1415.         OSErr        anErr = noErr;
  1416.         anErr = MAInteractWithUser(); 
  1417.         if (anErr == errAENoUserInteraction)
  1418.         {
  1419.             // No interaction is allowed so just attempt to resolve the alias without UI.
  1420.             FSSpec        theFileSpec;            // Resulting file spec goes here.
  1421.             Boolean        updateAlias = FALSE;
  1422.             short        myMatchCount = 1;
  1423.     
  1424.             // First try the absolute search method.
  1425.             anErr = MatchAlias(NULL,                    // fromFile
  1426.                                 kARMMountVol
  1427.                                     + kARMSearch
  1428.                                     + kARMNoUI,            // rulesMask
  1429.                                 fAlias,                    // alias
  1430.                                 &myMatchCount,            // aliasCount
  1431.                                 &theFileSpec,            // aliasList (FSSpecArrayPtr)
  1432.                                 &updateAlias,            // needsUpdate
  1433.                                 NULL,                    // aliasFilter
  1434.                                 NULL);                    // yourDataPtr);
  1435.         }
  1436.         else
  1437.             anErr = ResolveAlias(NULL, fAlias, &fFileSpec, &wasChanged);
  1438.  
  1439.         if (anErr != userCanceledErr)
  1440.             FailOSErr(anErr);
  1441.     }
  1442.  
  1443.     return wasChanged;
  1444. }
  1445.  
  1446. //----------------------------------------------------------------------------------------
  1447. // TFile::UpdateResource: 
  1448. //----------------------------------------------------------------------------------------
  1449. #pragma segment MAFileNonRes
  1450.  
  1451. OSErr TFile::UpdateResource()
  1452. {
  1453.     UpdateResFile(fRsrcRefNum);
  1454.     return ResError();
  1455. } // TFile::UpdateResource 
  1456.  
  1457. //----------------------------------------------------------------------------------------
  1458. // TFile::UseResource: 
  1459. //----------------------------------------------------------------------------------------
  1460. #pragma segment MAFileNonRes
  1461.  
  1462. short TFile::UseResource()
  1463. {
  1464.     return MAUseResFile(fRsrcRefNum);
  1465. } // TFile::UseResource 
  1466.  
  1467. //----------------------------------------------------------------------------------------
  1468. // TFile::WriteData: 
  1469. //----------------------------------------------------------------------------------------
  1470. #pragma segment MAFileWrite
  1471.  
  1472. OSErr TFile::WriteData(const void* buffer,
  1473.                               long& count)
  1474. {
  1475.     return FSWrite(fDataRefNum, &count, buffer);
  1476. } // TFile::WriteData 
  1477.  
  1478. //----------------------------------------------------------------------------------------
  1479. // TFile::GetObjectProperty: 
  1480. //----------------------------------------------------------------------------------------
  1481. #pragma segment MAScriptingRes
  1482.  
  1483. Boolean TFile::GetObjectProperty(CAEDesc& thePropertyValue,
  1484.                                  DescType whichProperty,
  1485.                                  const CAEDesc& desiredType)
  1486. {
  1487.     Boolean hasProperty = TRUE;
  1488.     FailInfo fi;
  1489.     Try(fi)
  1490.     {
  1491.         switch (whichProperty)
  1492.         {
  1493.             case pName:
  1494.                 {
  1495.                     CStr255 thePathName;
  1496.                     if (this->GetPathName(thePathName) == noErr)
  1497.                     {
  1498.                         CStr63 theFileName;
  1499.                         this->GetName(theFileName);
  1500.                         thePropertyValue.PutString(thePathName + theFileName);
  1501.                     }
  1502.                     break;
  1503.                 }
  1504.     
  1505.             case pIsStationeryPad:
  1506.                 thePropertyValue.PutBoolean(this->IsStationery());
  1507.                 break;
  1508.     
  1509.             default:
  1510.                 hasProperty = MScriptableObject::GetObjectProperty(thePropertyValue, whichProperty, desiredType);
  1511.                 break;
  1512.         }
  1513.         fi.Success();
  1514.     }
  1515.     else
  1516.     {
  1517.         hasProperty = FALSE;
  1518.     }
  1519.     return hasProperty;
  1520. }
  1521.  
  1522. //----------------------------------------------------------------------------------------
  1523. // TFile::SetObjectProperty: 
  1524. //----------------------------------------------------------------------------------------
  1525. #pragma segment MAScriptingRes
  1526.  
  1527. void TFile::SetObjectProperty(const CAEDesc& thePropertyValue,
  1528.                               DescType whichProperty)
  1529. {
  1530.     switch (whichProperty)
  1531.     {
  1532.         case pName:
  1533.         case pIsStationeryPad:
  1534.             FailOSErr(errAECantSetReadOnly);
  1535.             break;
  1536.  
  1537.         default:
  1538.             MScriptableObject::SetObjectProperty(thePropertyValue, whichProperty);
  1539.             break;
  1540.     }
  1541. }
  1542.  
  1543. //----------------------------------------------------------------------------------------
  1544. // End of UFile.cp
  1545.  
  1546. #pragma segment Inline
  1547.